package com.tea.funct.controller;

import com.tea.common.annotation.Log;
import com.tea.common.core.controller.BaseController;
import com.tea.common.core.domain.AjaxResult;
import com.tea.common.core.page.TableDataInfo;
import com.tea.common.enums.BusinessType;
import com.tea.common.utils.poi.ExcelUtil;
import com.tea.funct.domain.TeaPriceDetails;
import com.tea.funct.service.ITeaPriceDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 价格明细Controller
 *
 * @author Sophia
 * @date 2024-05-25
 */
@RestController
@RequestMapping("/funct/pdetails")
public class TeaPriceDetailsController extends BaseController {
    @Autowired
    private ITeaPriceDetailsService teaPriceDetailsService;

    /**
     * 查询价格明细列表
     */
    @PreAuthorize("@ss.hasPermi('funct:details:list')")
    @GetMapping("/list")
    public TableDataInfo list(TeaPriceDetails teaPriceDetails) {
        startPage();
        List<TeaPriceDetails> list = teaPriceDetailsService.selectTeaPriceDetailsList(teaPriceDetails);
        return getDataTable(list);
    }

    /**
     * 导出价格明细列表
     */
    @PreAuthorize("@ss.hasPermi('funct:details:export')")
    @Log(title = "价格明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeaPriceDetails teaPriceDetails) {
        List<TeaPriceDetails> list = teaPriceDetailsService.selectTeaPriceDetailsList(teaPriceDetails);
        ExcelUtil<TeaPriceDetails> util = new ExcelUtil<TeaPriceDetails>(TeaPriceDetails.class);
        util.exportExcel(response, list, "价格明细数据");
    }

    /**
     * 获取价格明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('funct:details:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(teaPriceDetailsService.selectTeaPriceDetailsById(id));
    }

    /**
     * 新增价格明细
     */
    @PreAuthorize("@ss.hasPermi('funct:details:add')")
    @Log(title = "价格明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeaPriceDetails teaPriceDetails) {
        return toAjax(teaPriceDetailsService.insertTeaPriceDetails(teaPriceDetails));
    }

    /**
     * 修改价格明细
     */
    @PreAuthorize("@ss.hasPermi('funct:details:edit')")
    @Log(title = "价格明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeaPriceDetails teaPriceDetails) {
        return toAjax(teaPriceDetailsService.updateTeaPriceDetails(teaPriceDetails));
    }

    /**
     * 删除价格明细
     */
    @PreAuthorize("@ss.hasPermi('funct:details:remove')")
    @Log(title = "价格明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(teaPriceDetailsService.deleteTeaPriceDetailsByIds(ids));
    }
}
